//
//  MovieCollectionViewCell.m
//  Fengly_Nuo_Movie
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 Fengly_Nuo. All rights reserved.
//

#import "MovieCollectionViewCell.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"

// MARK:VIEW_CENTER_X:屏中心x轴
#define VIEW_CENTER_X self.contentView.center.x

// MARK:VIEW_CENTER_Y:屏中心y轴
#define VIEW_CENTER_Y self.contentView.center.y

// MARK:HEIGHT:屏高
#define HEIGHT self.contentView.frame.size.height

// MARK:WIDTH:屏宽
#define WIDTH self.contentView.frame.size.width


@implementation MovieCollectionViewCell


- (void)setModel:(MovieModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
        
        [self assignment];
    }
}

- (void)assignment {
    [_movieImage sd_setImageWithURL:[NSURL URLWithString:_model.image]];
    _movieTitleLabel.text = _model.title;
    _movieTitleLabel.textAlignment = NSTextAlignmentCenter;
}



- (void)dealloc {
    [_model release];
    [_movieImage release];
    [_movieTitleLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createMoviewCell];
    }
    return self;
}

- (void)createMoviewCell {
    self.movieImage = [[UIImageView alloc] init];
    [self.contentView addSubview:_movieImage];
    [_movieImage release];
    
    self.movieTitleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_movieTitleLabel];
    [_movieTitleLabel release];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    _movieImage.frame = CGRectMake(0, 0, WIDTH, 8 * (HEIGHT / 10));
//    _movieImage.backgroundColor = [UIColor cyanColor];
    
    _movieTitleLabel.frame = CGRectMake(0, _movieImage.frame.size.height, WIDTH, 2 * HEIGHT / 10);
//    _movieTitleLabel.backgroundColor = [UIColor yellowColor];
    
    
}

@end
